home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1995 August / macformat-027.iso / mac / Shareware City / Developers / Oberon⁄F / Samples / Mod / Ex1 (.txt) < prev    next >
Encoding:
Oberon Document  |  1994-06-07  |  3.8 KB  |  55 lines  |  [oODC/obnF]

  1. Documents.StdDocumentDesc
  2. Documents.DocumentDesc
  3. Containers.ViewDesc
  4. Views.ViewDesc
  5. Stores.StoreDesc
  6. Documents.ModelDesc
  7. Containers.ModelDesc
  8. Models.ModelDesc
  9. Stores.ElemDesc
  10. TextViews.StdViewDesc
  11. TextViews.ViewDesc
  12. TextModels.StdModelDesc
  13. TextModels.ModelDesc
  14. TextModels.AttributesDesc
  15. Geneva
  16. Geneva
  17. L Frutiger Light
  18. Geneva
  19. TextRulers.StdRulerDesc
  20. TextRulers.RulerDesc
  21. TextRulers.StdStyleDesc
  22. TextRulers.StyleDesc
  23. TextRulers.AttributesDesc
  24. MODULE SamplesEx1;
  25.     IMPORT Views, TextModels, TextMappers, TextViews;
  26.     PROCEDURE Do*;
  27.         VAR t: TextModels.Model; f: TextMappers.Formatter; v: TextViews.View;
  28.     BEGIN
  29.         t := TextModels.dir.New();    (* create a new, empty text *)
  30.         f.ConnectTo(t);    (* connect a formatter to the text *)
  31.         f.WriteString("Hello World"); f.WriteLn;    (* write string and 0DX into new text *) 
  32.         v := TextViews.dir.New(t);    (* create a new text view for t *)
  33.         Views.Open(v, NIL, "")    (* open the view in a window *)
  34.     END Do;
  35. END SamplesEx1.
  36. TextControllers.StdCtrlDesc
  37. TextControllers.ControllerDesc
  38. Containers.ControllerDesc
  39. Controllers.ControllerDesc
  40. Geneva
  41. Example 1
  42. Everything in Oberon revolves around views. A view is a rectangular part of a document; documents consist of a hierarchy of nested views. This text is a text view; below is another text view embedded in it:
  43. The embedded text view above contains a slightly more advanced hello world program than the one in Ex0. It doesn't use module Out to write into the log window; instead it creates a new empty text, to which it connects a text formatter. A text formatter is an object which provides procedures to write variables of all basic Oberon types into a text. In the above example, a string and a carriage return are written to the text, which means that they are appended to the existing text. Since a newly created text is empty, t now contains exactly what the formatter has written into it.
  44. A text is an object which carries text and text attributes; i.e. a sequence of characters and information about font, color, and vertical offset of each character. However, a text does not know how to draw itself; this is the purpose of a text view. (Yes, what you are currently looking at is the output of such a view.) When a text view is created, it receives the text to be displayed as a parameter. Several views on the same text can be open simultaneously, as you can see when you execute New
  45. Window in the Windows menu. When you edit in one window, the changes are propagated to all other windows on the same text.
  46. When you create a text, you can follow the steps outlined below:
  47. 1) create a text model
  48. 2) connect a text formatter to it
  49. 3) write the text's context via the formatter
  50. 4) create a text view for the model
  51. 5) open the text view in a window
  52. In this example, we have seen how to use the text subsystem in order to create a new text.
  53. Geneva
  54. Documents.ControllerDesc
  55.